package functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.method;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.ArrayList;
import java.util.List;
import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.units.AnnotatedGene;
import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.units.GoTerm;

/**
 *
 * @author jamiemacpherson
 */
public class TermOverlap implements SemanticSimilarityMeasure {

    public Integer getSimilarity(AnnotatedGene gene1, AnnotatedGene gene2) {
        List<GoTerm> allTerms_this = gene1.getAllTermsIncludingParents();
        if (allTerms_this.size() == 0) {
            return 0;
        }
        List<GoTerm> allTerms_other = gene2.getAllTermsIncludingParents();
        if (allTerms_other.size() == 0) {
            return 0;
        }
        List<GoTerm> terms_shared = new ArrayList<GoTerm>();
        terms_shared.addAll(allTerms_this);
        terms_shared.retainAll(allTerms_other);
        return terms_shared.size() - 1;
    }
}
